package com.example.black.myapplication.materia;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.black.myapplication.R;

public class NavigationActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private DrawerLayout draw;
    private LinearLayout containerLayout;
    private Button btn;
    private Button startNv;
    private ActionBarDrawerToggle drawerToggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);
        initView();
    }

    private void initView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        draw = (DrawerLayout) findViewById(R.id.draw);
        containerLayout = (LinearLayout) findViewById(R.id.container_layout);
        btn = (Button) findViewById(R.id.btn);
        startNv = (Button) findViewById(R.id.startNv);
        drawerToggle = new ActionBarDrawerToggle(
                this,
                draw
                , toolbar
                , R.string.drawer_open
                , R.string.drawer_close
        );
        draw.addDrawerListener(drawerToggle);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                draw.openDrawer(Gravity.LEFT);
            }
        });

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // 需要将ActionDrawerToggle与DrawerLayout的状态同步
        // 将ActionBarDrawerToggle中的drawer图标，设置为ActionBar中的Home-Button的Icon
        drawerToggle.syncState();
    }
}
